from django.urls import path, re_path
from rest_framework_jwt.views import obtain_jwt_token
from meiduo_admin.views import home_views, user_views, sku_views, spu_views, specification_views, channel_views, \
    brand_views, skuimages_views, order_views, permission_views, usergroup_views, admin_views

urlpatterns = [
    # 登陆
    # path('authorizations/', LoginView.as_view()),
    # 使用jwt拓展插件提供的obtain_jwt_token视图来完成用户名和密码校验以及签发token
    # 注意：我们需要自定义一个响应参数构造函数
    path("authorizations/", obtain_jwt_token),

    # 用户总量统计
    path("statistical/total_count/", home_views.UserTotalCountView.as_view()),
    # 日增用户统计
    path("statistical/day_increment/", home_views.UserDayCountView.as_view()),
    # 日活跃用户统计
    path("statistical/day_active/", home_views.UserActiveCountView.as_view()),
    # 日下单用户量统计
    path("statistical/day_orders/", home_views.UserOrderCountView.as_view()),
    # 月增用户统计
    path("statistical/month_increment/", home_views.UserMonthCountView.as_view()),
    # 日分类商品访问量
    path("statistical/goods_day_views/", home_views.GoodsDayView.as_view()),

    # 用户列表、查询用户、增加用户
    path("users/", user_views.UserView.as_view()),

    # SKU表数据列表、查询、新建
    path("skus/", sku_views.SKUGoodsView.as_view({"get": "list", "post": "create"})),
    # 获取sku的第三级分类信息
    path("skus/categories/", sku_views.SKUCategorieView.as_view()),
    # 获取spu表名称数据
    path("goods/simple/", sku_views.SPUSimpleView.as_view()),
    # 获取SPU商品规格信息
    path("goods/<int:pk>/specs/", sku_views.SPUSpecView.as_view()),
    # SKU表数据 单一对象查找、更新、删除
    path("skus/<int:pk>/", sku_views.SKUGoodsView.as_view({"get": "retrieve", "put": "update", "delete": "destroy"})),

    # SPU表数据 表列、新建
    path("goods/", spu_views.SPUGoodsView.as_view({"get": "list", "post": "create"})),
    # 获取品牌信息
    path("goods/brands/simple/", spu_views.SPUBrandView.as_view()),
    # 获取商品分类信息 一级
    path("goods/channel/categories/", spu_views.ChannelCategoryView.as_view()),
    # 获取商品分类信息 二级、三级
    path("goods/channel/categories/<int:pk>/", spu_views.ChannelCategoryView.as_view()),
    # SPU表数据 单一对象查找、更新、删除
    path("goods/<int:pk>/", spu_views.SPUGoodsView.as_view({"get": "retrieve", "put": "update", "delete": "destroy"})),

    # 规格表数据 列表、新建
    path("goods/specs/", specification_views.SpecsView.as_view({"get": "list", "post": "create"})),
    # 规格表数据 单一对象查找、更新、删除
    path("goods/specs/<int:pk>/",
         specification_views.SpecsView.as_view({"get": "retrieve", "put": "update", "delete": "destroy"})),

    # 规格选项表数据 列表、新建
    path("specs/options/", specification_views.OptionsView.as_view({"get": "list", "post": "create"})),
    # 获取商品规格名称
    path("goods/specs/simple/", specification_views.OptionSimple.as_view()),
    # 规格选项表数据 单一对象查找、更新、删除
    path("specs/options/<int:pk>/",
         specification_views.OptionsView.as_view({"get": "retrieve", "put": "update", "delete": "destroy"})),

    # 商品频道表 列表、新建
    path("goods/channels/", channel_views.ChannelView.as_view({"get": "list", "post": "create"})),
    # 获取商品频道分组信息
    path("goods/channel_types/", channel_views.ChannelGroupView.as_view()),
    # 获取商品分类信息 一级
    path("goods/categories/", spu_views.ChannelCategoryView.as_view()),
    # 商品频道表 单一对象查找、更新、删除
    path("goods/channels/<int:pk>/",
         channel_views.ChannelView.as_view({"get": "retrieve", "put": "update", "delete": "destroy"})),

    # 品牌表 列表、新建
    path("goods/brands/", brand_views.BrandView.as_view({"get": "list", "post": "create"})),
    # 品牌表 单一对象查找、更新、删除
    path("goods/brands/<int:pk>/",
         brand_views.BrandView.as_view({"get": "retrieve", "put": "update", "delete": "destroy"})),

    # SKU图片表 列表、新建
    path("skus/images/", skuimages_views.SKUImagesView.as_view({"get": "list", "post": "create"})),
    # 获取sku名称
    # path("skus/simple/", skuimages_views.SKUSimpleView.as_view()),                 # 方法① 重新定义视图
    path("skus/simple/", skuimages_views.SKUImagesView.as_view({"get": "simple"})),  # 方法② 自定义action动作
    # SKU图片表 单一对象查找、更新、删除
    # 三种方法：① 在视图中重写create；② 在序列化器中重写validate；③ 在fastdfs.py的_save方法中定义全局（复用性广）
    path("skus/images/<int:pk>/",
         skuimages_views.SKUImagesView.as_view({"get": "retrieve", "put": "update", "delete": "destroy"})),

    # 订单表 列表
    path("orders/", order_views.OrdersView.as_view({"get": "list"})),
    # 订单表 单一对象查找
    path("orders/<int:pk>/", order_views.OrdersView.as_view({"get": "retrieve"})),
    # # 订单表 单一对象部分更新
    path("orders/<int:pk>/status/", order_views.OrdersView.as_view({"patch": "partial_update"})),

    # 用户权限表 列表、新建
    path("permission/perms/", permission_views.PermissionView.as_view({"get": "list", "post": "create"})),
    # 获取权限类型列表
    path("permission/content_types/", permission_views.PermissionView.as_view({"get": "content_types"})),
    # 用户权限表 单一对象查找、更新、删除
    path("permission/perms/<int:pk>/",
         permission_views.PermissionView.as_view({"get": "retrieve", "put": "update", "delete": "destroy"})),

    # 用户组表 列表、新建
    path("permission/groups/", usergroup_views.GroupView.as_view({"get": "list", "post": "create"})),
    # 获取权限列表
    path("permission/simple/", usergroup_views.GroupView.as_view({"get": "simple"})),
    # 用户组表 单一对象查找、更新、删除
    path("permission/groups/<int:pk>/",
         usergroup_views.GroupView.as_view({"get": "retrieve", "put": "update", "delete": "destroy"})),

    # 运营用户(商家) 列表、新建
    path("permission/admins/", admin_views.AdminView.as_view({"get": "list", "post": "create"})),
    # 获取分组表数据
    path("permission/groups/simple/", admin_views.GroupSimpleView.as_view({"get": "list"})),
    # 运营用户(商家) 单一对象查找、更新、删除
    path("permission/admins/<int:pk>/",
         admin_views.AdminView.as_view({"get": "retrieve", "put": "partial_update", "delete": "destroy"})),

]
